<?php

namespace EShop\Controller;

/**
 * MyProfileController 类
 *
 * @since VER:1.0; DATE:2016-9-1; AUTHOR:SoChishun; EMAIL:14507247@qq.com; DESC:Added.
 */
class ProfileController extends AppbaseMyController {
    function profile_edit(){
        $user=new \XWAM\Model\UserModel();
        $data=$user->find($this->user_login_data['id']);
        $this->assign('data',$data);
        $this->display('UC/Profile/profile_edit');
    }
    function profile_edit_save(){
        $data=array();
        $afield=array('sex','email','qq','mobile');
        foreach($afield as $field){
            $data[$field]=I($field);
        }
        if(!$data){
            exit('表单内容无效!');
        }
        $data['id']=$this->user_login_data['id'];
        $user=new \XWAM\Model\UserModel();
        $user->save($data);
        $this->success('保存成功!',U('profile_edit'));
    }
    function update_password_save(){
        $oldpwd=I('old_password');
        $newpwd=I('new_password');
        $repwd=I('comfirm_password');
        if(!$oldpwd || !$newpwd || !$repwd){
            $this->error('表单填写不完整!');
        }
        if($newpwd !=$repwd){
            $this->error('两次密码输入不一致!');
        }        
        $user=new \XWAM\Model\UserModel();
        $user->update_password($this->user_login_data['id'], $newpwd);
        $this->success('密码修改成功!',U('profile_edit'));
    }
    
}
